/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uit_vendor_management;

/**
 *
 * @author QuangKhoi
 */
public class Language {
    private static String[][] languageCode = new String[][] { {"en", "English"},
                                                           {"vi", "Vietnamese"} };
    public static String CurrentLanguage = "vi";
    public static String _(String _Word)
    {
        String SQL = "SELECT " + LanguageName(CurrentLanguage) +
            " FROM Translations WHERE Pharse = '" + _Word + "'";
        QueryResult result = Database.instance.Query(SQL);
        if (result.Count > 0) {
            String rs = result.Table.getString(0, 0);
            if (rs == null) rs = _Word;
            if (result.ReturnCode == 200)
                return rs;
        }
        return _Word;
    }

    public static String LanguageName(String _LanguageCode) {
        if (_LanguageCode == null) _LanguageCode = "en";
        for (int i = 0; i < languageCode.length; i++)
            if (languageCode[i][0].toString().equals(_LanguageCode))
                return languageCode[i][1];
        return _LanguageCode;
    }

    public static String LanguageCode(String _LanguageName)
    {
        if (_LanguageName == null) _LanguageName = "English";
        for (int i = 0; i < languageCode.length / 2; i++)
            if (languageCode[i][1].toString().endsWith(_LanguageName)) return languageCode[i][0];
        return _LanguageName;
    }
}
